<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文章列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <p>标题：</p>
                            <input type="text" name="title"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="article:article:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="article:article:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="article:article:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="article:article:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('article:article:edit')}]];
    var removeFlag = [[${@permission.hasPermi('article:article:remove')}]];
    var checkFlag = [[${@permission.hasPermi('article:article:check')}]];
    var publishFlag = [[${@permission.hasPermi('article:article:publish')}]];
    var transferFlag = [[${@permission.hasPermi('article:article:transfer')}]];
    var isShowDatas = [[${@dict.getType('sys_show_hide')}]];
    var isTvShowDatas = [[${@dict.getType('sys_show_hide')}]];
    var isWxShowDatas = [[${@dict.getType('sys_show_hide')}]];
    var isPcShowDatas = [[${@dict.getType('sys_show_hide')}]];
    var isShowIndexDatas = [[${@dict.getType('sys_show_hide')}]];
    var isPublishDatas = [[${@dict.getType('sys_show_hide')}]];
    var isCheckDatas = [[${@dict.getType('sys_show_hide')}]];
    var isFinalCheckDatas = [[${@dict.getType('sys_check_status')}]];
    var isDelDatas = [[${@dict.getType('sys_show_hide')}]];
    var prefix = ctx + "article/article";

    $(function () {
        var options = {
            url: prefix + "/list/" + [[${menuId}]],
            createUrl: prefix + "/add/" + [[${menuId}]],
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            checkUrl: prefix + "/check",
            publishUrl: prefix + "/publish",
            modalName: "文章",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'isFinalCheck',
                    title: '终审状态',
                    visible: false
                },
                {
                    field: 'isPublish',
                    title: '是否发布',
                    visible: false
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'menu.menuName',
                    title: '栏目名称'
                },
                {
                    field: 'dept.deptName',
                    title: '区域名称'
                },
                {
                    field: 'publishTime',
                    title: '投稿时间'
                },
                {
                    field: 'user.loginName',
                    title: '发布人'
                },
                {
                    field: 'isFinalCheck',
                    title: '是否通过审核',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(isFinalCheckDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if (row.isFinalCheck == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="check(\'' + row.id + '\')"><i class="fa fa-edit"></i>终审</a>');
                        }
                        if (row.isFinalCheck == 1) {
                            actions.push('<a class="btn btn-danger btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="cancelFinalCheck(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消终审</a>');
                            if (row.isPublish == 0) {
                                actions.push('<a class="btn btn-info btn-xs ' + publishFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id + '\')"><i class="fa fa-plus"></i>发布</a> ');
                            } else if (row.isPublish == 1) {
                                actions.push('<a class="btn btn-danger btn-xs ' + publishFlag + '" href="javascript:void(0)" onclick="publish(\'' + row.id + '\')"><i class="fa fa-remove"></i>取消发布</a> ');
                            }
                        }
                        actions.push('<a class="btn btn-success btn-xs ' + transferFlag + '" href="javascript:void(0)" onclick="transfer(\'' + row.id + '\')"><i class="fa fa-edit"></i>转移区域</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function check(id) {
        var url = prefix + "/check/" + id;
        $.modal.open("列表", url, "720", "600")
    }

    function transfer(id) {
        var url = prefix + "/transfer/" + id;
        $.modal.open("列表", url, "600", "480")
    }
    function cancelFinalCheck(id) {
        table.set();
        $.modal.confirm("确定取消终审吗？", function () {
            var url = prefix + "/cancelFinalCheck";
            if (table.options.type == table_type.bootstrapTreeTable) {
                $.operate.get(url);
            } else {
                var data = {"id": id};
                $.operate.submit(url, "post", "json", data);
            }
        });
        /*$.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: prefix + "/cancelFinalCheck",//url
            data: {"id": id},
            cache: false,
            success: function (data) {           //成功回调
              /!*  $(parent.$("#position")).attr("value", data.title);
                $(parent.$("#hideinfo")).attr("value", data.position);*!/
                setTimeout(function () {
                    $.modal.close();
                }, 300);
            }
        })*/
    }

    function publish(id) {
        var url = prefix + "/publish";
        var data = {"id": id};
        $.operate.submit(url, "post", "json", data);
    }
</script>
</body>
</html>